package com.gzdh.dishrecognition.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gzdh.dishrecognition.R;
import com.gzdh.dishrecognition.entity.BmcmEntity;
import com.gzdh.dishrecognition.entity.FkEntity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class FkInfoAdapter extends RecyclerView.Adapter<FkInfoAdapter.ViewHolder> {

    private Context mcontext;

    private List<FkEntity> list;

    public FkInfoAdapter(Context context) {
        mcontext = context;
        this.list = new ArrayList<>();
    }


    public void setList(List<FkEntity> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fk_info, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        holder.cardNoTv.setText(list.get(position).getCardno().trim());
        holder.nameTv.setText(list.get(position).getName());
        holder.cardSnTv.setText(list.get(position).getCardsn());
        holder.kyeTv.setText(list.get(position).getKye());
        holder.btyeTv.setText(list.get(position).getBtye());
        try{
            holder.validdateTv.setText(sdf.format(list.get(position).getValiddate()));
        }catch (Exception e){
            holder.validdateTv.setText("");
        }

        if (position % 2 == 0) {
            holder.mainLinear.setBackgroundColor(Color.rgb(255, 255, 255));
        } else {
            holder.mainLinear.setBackgroundColor(Color.rgb(200, 200, 200));
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mainLinear;

        TextView cardNoTv;
        TextView nameTv;
        TextView cardSnTv;
        TextView kyeTv;
        TextView btyeTv;
        TextView validdateTv;

        ViewHolder(View item) {
            super(item);
            mainLinear = item.findViewById(R.id.mainLinear);

            cardNoTv = item.findViewById(R.id.cardNoTv);
            nameTv = item.findViewById(R.id.nameTv);
            cardSnTv = item.findViewById(R.id.cardSnTv);
            kyeTv = item.findViewById(R.id.kyeTv);
            btyeTv = item.findViewById(R.id.btyeTv);
            validdateTv = item.findViewById(R.id.validdateTv);
        }

    }


}
